import RTCChannel from "./RTCChannel";

class RTCCloudApp {
    constructor(containerId, options) {
        this.options = {containerId: containerId, ...options}
        this.rtcChannel = new RTCChannel(this.options);
        this.rtcChannel.init();

        window.addEventListener('pagehide', () => {
            this.exit();
        });
    }

    getVolume() {
        return this.rtcChannel.getVolume();
    }

    setVolume(value) {
        this.rtcChannel.setVolume(value);
    }

    exit() {
        this.rtcChannel.destroy();
    }

    pause() {
        this.rtcChannel.pause();
    }

    resume() {
        this.rtcChannel.resume();
    }

    reconnect() {
        this.rtcChannel.reconnect();
    }

    fullscreenToggle(fullscreenElementId) {
        this.rtcChannel.fullscreenToggle(fullscreenElementId);
    }

    isFullscreen() {
        return this.rtcChannel.isFullscreen();
    }

    on(eventName, callback) {
        this.rtcChannel.on(eventName, callback);
    }

    off(eventName, callback) {
        this.rtcChannel.off(eventName, callback);
    }

    setResolution(clarityVal) {
        this.rtcChannel.setResolution(clarityVal);
    }

    setMediaConfig(config) {
        this.rtcChannel.setMediaConfig(config);
    }

    sendDataToCloudApp(data) {
        this.rtcChannel.sendMessage(data);
    }
}

export default RTCCloudApp